package com.yc.rh.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.yc.rh.dao.IUserInfoDao;
import com.yc.rh.entities.PageInfo;
import com.yc.rh.entities.UserInfo;

public class UserInfoDaoImpl implements IUserInfoDao{
	private SqlSession sqlSession;
	
	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}
	
	@Override
	public int addUserInfo(UserInfo uf) {
		return sqlSession.insert("addUserInfo",uf);
	}

	@Override
	public int checkEmail(String email) {
		return sqlSession.selectOne("checkEmail", email);
	}

	@Override
	public List<String> getAlleMmail() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public UserInfo loginUserInfo(UserInfo uf) {
		return sqlSession.selectOne("userInfoLogin", uf);
	}

	@Override
	public List<UserInfo> findUserInfoByPage(PageInfo pageInfo) {
		return sqlSession.selectList("findUserInfoByPage", pageInfo);
	}

	@Override
	public List<UserInfo> findUserInfo(Map<String, String> map, Integer pageNo, Integer pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<UserInfo> findUserInfoByDate(String startDate, String endDate, Integer pageNo, Integer pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int updatePwd(String usid, String cldPwd, String newPwd) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int update(UserInfo uf) {
		return sqlSession.update("updateUserInfo",uf);
	}

	@Override
	public int delUserInfo(String usid) {
		List<Integer> list=new ArrayList<Integer>();
		while(usid.contains(",")){
			Integer userid=Integer.valueOf(usid.substring(0, usid.indexOf(",")));
			usid=usid.substring(usid.indexOf(",")+1);
			list.add(userid);
		}
		list.add(Integer.valueOf(usid));
		return sqlSession.delete("delUserInfo",list);
	}

	@Override
	public int getTotal() {
		return sqlSession.selectOne("getUserTotal");
	}

	@Override
	public String findUnameByUsid(int usid) {
		return sqlSession.selectOne("getUnameByUsid", usid);
	}
}
